<?php
	include '../init.php';
	$data = array(
		'title'=>addslashes($_POST['title']),
		'siteurl'=>addslashes($_POST['siteurl']),
		'keyword'=>addslashes($_POST['keyword']),
		'description'=>addslashes($_POST['description']),
		'sitelogo'=>$_POST['sitelogo'],
		'siteqq'=>addslashes($_POST['siteqq']),
		'weichat'=>addslashes($_POST['weichat']),
		'address'=>addslashes($_POST['address']),
		'status'=>(int)$_POST['status'],
		);
	
	//如果获取到ID则更新数据，否则新建数据
	if(isset($_POST['id'])&&(int)$_POST['id']>0){

	}else{
		foreach ($data as $key => $value) {
			$sql = "SELECT * FROM setting WHERE settingkey='{$key}'";
			$row = $mysql->getRow($sql);
			$sdata=array();
			if($row){
				$sql = "UPDATE setting SET settingvalue='{$value}' WHERE settingkey='{$key}'";
				$mysql->query($sql);
			}else{
				$sdata=array('settingkey'=>$key,'settingvalue'=>$value);
				$mysql->addRow('setting',$sdata);
			}
			
		}
		echo json_encode(array('code'=>'000','msg'=>'保存成功'));
	}
	
?>